home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / collectionUI.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.8 KB  |  613 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  December 8/2000
  22. //  Author:         jdc rendering
  23. //
  24. // Description:
  25. //
  26. //        This file contains the procedures which implement a portable (can be
  27. //        used anywhere) user interface for viewing collections of nodes in the
  28. //        current Maya scene using a graphical layout. This file also contains 
  29. //        the procedures used to manipulate that user interface once it has been 
  30. //        created.
  31. //                                                
  32.  
  33. // ---------------------------------------------------------------------------
  34. // Special names and things like that
  35. //
  36. // "collectionForm": the name of the form which contains the graph
  37. // 
  38.  
  39. // ---------------------------------------------------------------------------
  40. // Local procedures
  41. // 
  42.  
  43. global string $gCollectionUILookupTable[];
  44. global int $gCollectionUILookupTableCreated = false;
  45.  
  46. proc createCollectionUILookupTable()
  47. {
  48.     //
  49.     // Description:
  50.     //    This procedure is called every time the user creates a collectionUI
  51.     //    component, but only has any effect the first time it is called.
  52.     //    This procedure initializes the string array $gCollectionUILookupTable[]
  53.     //    for use as a lookup table. The lookup table will contain information
  54.     //    about all collectionUI components which exist in the current Maya
  55.     //    session.
  56.     //
  57.  
  58.     global string $gCollectionUILookupTable[];
  59.     global int $gCollectionUILookupTableCreated;
  60.  
  61.     if (!$gCollectionUILookupTableCreated)
  62.     {
  63.         // The lookup table has not yet been initialized, so we will do so now.
  64.         //
  65.         string $columns[];
  66.  
  67.         $columns[0] = "collectionUI";
  68.         $columns[1] = "hypershadeName";
  69.         $columns[2] = "popupMenuScript";
  70.         $columns[3] = "filter";
  71.  
  72.         lookupTable($gCollectionUILookupTable, $columns);
  73.         $gCollectionUILookupTableCreated = true;
  74.     }
  75. }
  76.  
  77. proc registerCollectionUI(
  78.     string $collectionUI)
  79. {
  80.     //
  81.     // Description:
  82.     //    This procedure is used to register a collectionUI component by entering
  83.     //    it as a row in the lookup table which contains information about all
  84.     //    collectionUI components that currently exist in Maya.
  85.     //    The row created is initially blank except for the collectionUI name.
  86.     //    Further information about the collectionUI component must be
  87.     //    subsequently added to the lookup table.
  88.     //
  89.  
  90.     global string $gCollectionUILookupTable[];
  91.     string $row[];
  92.  
  93.     $row[0] = $collectionUI;
  94.     $row[1] = "";
  95.     $row[2] = "";
  96.     $row[3] = "";
  97.  
  98.     lookupTableAddRow($gCollectionUILookupTable, $row);
  99. }
  100.  
  101. proc registerHypershadeName(
  102.     string $collectionUI,
  103.     string $hypershadeName)
  104. {
  105.     //
  106.     // Description:
  107.     //    This procedure associates the hypershadeName with the collectionUI 
  108.     //     in the lookup table.
  109.     //
  110.  
  111.     global string $gCollectionUILookupTable[];
  112.  
  113.     // ASSUMPTION:
  114.     // We assume that a row already exists for this collectionUI, as it should
  115.     // have been created by a call to registerCollectionUI() as the UI was being
  116.     // created.
  117.     //
  118.     lookupTableEdit(
  119.         $gCollectionUILookupTable,
  120.         "collectionUI",
  121.         $collectionUI,
  122.         "hypershadeName",
  123.         $hypershadeName);
  124. }
  125.  
  126. proc string lookupHypershadeName(
  127.     string $collectionUI)
  128. {
  129.     //
  130.     // Description:
  131.     //    This procedure looks up the hypershade name associated with the
  132.     //    specified collectionUI name in the lookup table.
  133.     //
  134.     // Returns: 
  135.     //    The hypershade name, if one is associated with the specified
  136.     //    collection UI name.
  137.     //    Otherwise: "".
  138.     //
  139.  
  140.     global string $gCollectionUILookupTable[];
  141.  
  142.     return (lookupTableLookup(
  143.         $gCollectionUILookupTable,
  144.         "collectionUI",
  145.         $collectionUI,
  146.         "hypershadeName"));
  147. }
  148.  
  149. proc string generateUniqueHypershadeName()
  150. {
  151.     //
  152.     // Description:
  153.     //    This procedure is usually called just before creating a new hypershade
  154.     //    for a collectionUI.
  155.     //    This procedure generates a unique name for a hypershade by
  156.     //    creating a string of the form collection#HyperShadeEd and incrementing 
  157.     //    the # part until no hypershade by that name exists.
  158.     //
  159.     // Returns: 
  160.     //    A unique name by which a hypershade can be created.
  161.     //
  162.  
  163.     int $i = 1;
  164.     while (`hyperGraph -exists ("collection" + $i + "HyperShadeEd")`)
  165.     {
  166.         $i++;
  167.     }
  168.     return ("collection" + $i + "HyperShadeEd");
  169. }
  170.     
  171. proc registerFilter(
  172.     string $collectionUI,
  173.     string $filter)
  174. {
  175.     //
  176.     // Description:
  177.     //    This procedure associates the filter with the collectionUI 
  178.     //     in the lookup table.
  179.     //
  180.  
  181.     global string $gCollectionUILookupTable[];
  182.  
  183.     // ASSUMPTION:
  184.     // We assume that a row already exists for this collectionUI, as it should
  185.     // have been created by a call to registerCollectionUI() as the UI was being
  186.     // created.
  187.     //
  188.     lookupTableEdit(
  189.         $gCollectionUILookupTable,
  190.         "collectionUI",
  191.         $collectionUI,
  192.         "filter",
  193.         $filter);
  194. }
  195.  
  196. // ---------------------------------------------------------------------------
  197. // Global procedures
  198. // 
  199.  
  200. global proc string collectionUIHypershadeName(
  201.     string $collectionUI)
  202. {
  203.     //
  204.     // Description:
  205.     //    This procedure returns the name of the hypershade editor associated
  206.     //    with the specified collectionUI component.
  207.     //
  208.  
  209.     return lookupHypershadeName($collectionUI);
  210. }
  211.  
  212. global proc string collectionUIFilter(
  213.     string $collectionUI)
  214. {
  215.     //
  216.     // Description:
  217.     //    This procedure looks up the filter associated with the
  218.     //    specified collectionUI name in the lookup table.
  219.     //
  220.     // Returns: 
  221.     //    The hypershade name, if one is associated with the specified
  222.     //    collection UI name.
  223.     //    Otherwise: "".
  224.     //
  225.  
  226.     global string $gCollectionUILookupTable[];
  227.  
  228.     return (lookupTableLookup(
  229.         $gCollectionUILookupTable,
  230.         "collectionUI",
  231.         $collectionUI,
  232.         "filter"));
  233. }
  234.  
  235. global proc int collectionUIIsManaged(
  236.     string $collectionUI)
  237. {
  238.     //
  239.     // Description:
  240.     //    This procedure is used to query whether the overall layout of the
  241.     //    specified collectionUI component is managed or not. 
  242.     //
  243.     // Returns: 
  244.     //    This procedure returns true if the overall layout is managed, false if
  245.     //    not.
  246.     //
  247.  
  248.     return `formLayout -query -manage $collectionUI`;
  249. }
  250.  
  251. global proc collectionUIManage(
  252.     string $collectionUI,
  253.     int $manage)
  254. {
  255.     //
  256.     // Description:
  257.     //    This procedure lets the caller manage or unmanage the overall layout of
  258.     //    the specified collectionUI component.
  259.     //
  260.  
  261.     formLayout -edit -manage $manage $collectionUI;
  262. }
  263.  
  264. global proc string collectionUIPopupMenuScript(
  265.     string $collectionUI)
  266. {
  267.     //
  268.     // Description:
  269.     //    This procedure looks up the name of the popup menu script associated
  270.     //    with the specified collectionUI component.
  271.     //
  272.     // Returns: 
  273.     //    The name of the popup menu script.
  274.     //
  275.  
  276.     // Lookup the name of the popup menu script in the lookup table
  277.     //
  278.     global string $gCollectionUILookupTable[];
  279.  
  280.     return lookupTableLookup(
  281.         $gCollectionUILookupTable,
  282.         "collectionUI",
  283.         $collectionUI,
  284.         "popupMenuScript");
  285. }
  286.  
  287. global proc collectionUISetPopupMenuScript(
  288.     string $collectionUI,
  289.     string $scriptName)
  290. {
  291.     //
  292.     // Description:
  293.     //    This procedure sets the popup menu script which is invoked when the
  294.     //    user RMB clicks in the hyperShade element of the specified collectionUI
  295.     //    component. The script will be called with two arguments: the name of
  296.     //    the hyperShade editor from which the menu was invoked, and the name of
  297.     //    the popupMenu object to which the menu items are to be added.
  298.     //
  299.     //    If $scriptName is "", no popup menu will be invoked when the user RMB
  300.     //    clicks in the hyperShade editor.
  301.     //
  302.  
  303.     // Find the name of the control that the menu will be attached to
  304.     //
  305.     string $hypershadeName = lookupHypershadeName($collectionUI);
  306.  
  307.     string $parent                = `hyperGraph -query -control $hypershadeName`;
  308.     string $popupMenuName        = ($hypershadeName + "PopupMenu");
  309.  
  310.     if ($scriptName == "")
  311.     {
  312.         if (`popupMenu -exists $popupMenuName`) 
  313.         {
  314.             deleteUI $popupMenuName;
  315.         }
  316.     }
  317.     else
  318.     {
  319.         // Create the popup menu
  320.         //    
  321.         if (!`popupMenu -exists $popupMenuName`) 
  322.         {
  323.             string $fullMenuName = `popupMenu -parent $parent $popupMenuName`;
  324.             popupMenu 
  325.                 -edit
  326.                 -postMenuCommand 
  327.                     ($scriptName
  328.                         + " "
  329.                         + $hypershadeName 
  330.                         + " " 
  331.                         + $popupMenuName)
  332.                 $fullMenuName;    
  333.         }
  334.     }
  335.  
  336.     // Store the name of the popup menu script in the lookup table
  337.     // 
  338.     // ASSUMPTION:
  339.     // We assume that a row already exists for this collectionUI, as it should
  340.     // have been created by a call to registerCollectionUI() as the UI was being
  341.     // created.
  342.     //
  343.     global string $gCollectionUILookupTable[];
  344.  
  345.     lookupTableEdit(
  346.         $gCollectionUILookupTable,
  347.         "collectionUI",
  348.         $collectionUI,
  349.         "popupMenuScript",
  350.         $scriptName);
  351. }
  352.  
  353. global proc collectionUISetFilter(
  354.     string $collectionUI,
  355.     string $filter)
  356. {
  357.     //
  358.     // Description:
  359.     //    This procedure sets the filter which defines what nodes will appear in
  360.     //    the specified collectionUI component.
  361.     //
  362.  
  363.     string $hypershadeName = lookupHypershadeName($collectionUI);
  364.  
  365.     registerFilter($collectionUI, $filter);
  366.  
  367.     if ($filter == "Materials")
  368.     {
  369.         visor 
  370.             -addFolder 
  371.             -name "Materials"
  372.             -type command
  373.             -cmd "sort `lsThroughFilter DefaultMaterialsFilter`"
  374.             $hypershadeName;
  375.     }
  376.     else if ($filter == "MaterialsAndShaderGlow")
  377.     {
  378.         visor 
  379.             -addFolder 
  380.             -name "Materials and Shader Glow"
  381.             -type command
  382.             -cmd "sort `ls -type shaderGlow -materials`"
  383.             $hypershadeName;
  384.     }
  385.     else if ($filter == "Textures")
  386.     {
  387.         visor 
  388.             -addFolder 
  389.             -name "Textures"
  390.             -type command
  391.             -cmd "sort `lsThroughFilter DefaultTexturesFilter`"
  392.             $hypershadeName;
  393.     }
  394.     else if ($filter == "Cameras")
  395.     {
  396.         visor 
  397.             -addFolder 
  398.             -name "Cameras"
  399.             -type command
  400.             -cmd "sort `lsThroughFilter DefaultCameraShapesImagePlanesFilter`"
  401.             $hypershadeName;
  402.     }
  403.     else if ($filter == "Utilities")
  404.     {
  405.         visor 
  406.             -addFolder 
  407.             -name "Utilities"
  408.             -type command
  409.             -cmd "sort `lsThroughFilter DefaultRenderUtilitiesFilter`"
  410.             $hypershadeName;
  411.     }
  412.     else if ($filter == "Lights")
  413.     {
  414.         visor 
  415.             -addFolder 
  416.             -name "Lights"
  417.             -type command
  418.             -cmd "sort `lsThroughFilter DefaultAllLightsFilter`"
  419.             $hypershadeName;
  420.     }
  421.     else if ($filter == "LightsAndOpticalFX")
  422.     {
  423.         visor 
  424.             -addFolder 
  425.             -name "Lights and Optical FX"
  426.             -type command
  427.             -cmd "sort `lsThroughFilter DefaultLightsAndOpticalFXFilter`"
  428.             $hypershadeName;
  429.     }
  430.     else if ($filter == "ShadingGroups")
  431.     {
  432.         visor 
  433.             -addFolder 
  434.             -name "Shading Groups"
  435.             -type command
  436.             -cmd "sort `lsThroughFilter DefaultShadingGroupsFilter`"
  437.             $hypershadeName;
  438.     }
  439.     else if ($filter == "PostProcess")
  440.     {
  441.         visor 
  442.             -addFolder 
  443.             -name "Post Process"
  444.             -type command
  445.             -cmd "sort `ls -type opticalFX -type shaderGlow`"
  446.             $hypershadeName;
  447.     }
  448.     else if ($filter == "BakeSets")
  449.     {
  450.         visor 
  451.             -addFolder 
  452.             -name "Baking Sets"
  453.             -type command
  454.             -cmd "sort `lsThroughFilter DefaultBakeSetsFilter`"
  455.             $hypershadeName;
  456.     }
  457.     else if ($filter == "CharacterClips")
  458.     {
  459.         visor 
  460.             -addFolder 
  461.             -name "Character Clips"
  462.             -type command
  463.             -cmd "currentCharacterClips"
  464.             $hypershadeName;
  465.     }
  466.     else if ($filter == "CharacterPoses")
  467.     {
  468.         visor 
  469.             -addFolder 
  470.             -name "Character Poses"
  471.             -type command
  472.             -cmd "currentCharacterPoses"
  473.             $hypershadeName;
  474.     }
  475.     else if ($filter == "UnusedClips")
  476.     {
  477.         visor 
  478.             -addFolder 
  479.             -name "Unused Clips"
  480.             -type command
  481.             -cmd "unusedClips"
  482.             $hypershadeName;
  483.     }
  484.     else if ($filter == "UnusedPoses")
  485.     {
  486.         visor 
  487.             -addFolder 
  488.             -name "Unused Poses"
  489.             -type command
  490.             -cmd "unusedPoses"
  491.             $hypershadeName;
  492.     }
  493.     else
  494.     {
  495.         error ("Unrecognized filter type: " + $filter);
  496.     }
  497. }
  498.  
  499. // ---------------------------------------------------------------------------
  500. // Procedures for creating and deleting a graph UI
  501. // 
  502.  
  503. global proc collectionUIDelete(
  504.     string $collectionUI,
  505.     int $alsoDeleteHypershade)
  506. {
  507.     //
  508.     // Description:
  509.     //    This procedure deletes all UI associated with the specified
  510.     //    collectionUI component. 
  511.     //    If $alsoDeleteHypershade is true, the hyperShade editor associated
  512.     //    with the collectionUI component is also deleted. If
  513.     //    $alsoDeleteHypershade is false, the hyperShade editor is simply
  514.     //    unparented from the layout and will persist after the layout has been
  515.     //    deleted. Typically you would want to do this if you were deleting
  516.     //    the collectionUI component but planned to create an identical new one.
  517.     //    By not deleting the hyperShade editor, you will be able to reparent
  518.     //    it to the new collectionUI component, hence preserving the state of
  519.     //    things being displayed by that editor. See the description in
  520.     //    collectionUI() for more details.
  521.     //
  522.  
  523.     if (!$alsoDeleteHypershade)
  524.     {
  525.         // The caller has asked us not to delete the hypershade object along 
  526.         // with the UI, so we unparent it from the UI before we delete the UI.
  527.         //
  528.         string $hypershadeName = lookupHypershadeName($collectionUI);
  529.         hyperGraph -edit -unParent $hypershadeName;
  530.     }
  531.  
  532.     deleteUI $collectionUI;
  533. }
  534.  
  535. global proc string collectionUI(
  536.     string $parentFormLayout,
  537.     string $hypershadeName)
  538. {
  539.     //
  540.     // Description:
  541.     //    This procedure is called from any piece of UI which wants to create a
  542.     //    collection UI within itself. 
  543.     //    This procedure creates the collection UI.
  544.     //    If the stateDescription is specified, this code will use it to create 
  545.     //    a UI with the characteristics described therein.
  546.     //    In particular, this is designed to allow the collection UI to be moved 
  547.     //    from layout to layout without dramatically changing its appearance. 
  548.     //     Otherwise (if no stateDescription is provided), new UI is created with 
  549.     //     the default configuration.
  550.     //    The $reuseEditors argument is used to specify whether the hyperShade 
  551.     //     editor whose name is contained in the $stateDescription should be
  552.     //     parented to the new UI rather than creating a new hyperShade editor.
  553.     //
  554.     // Returns: 
  555.     //    This method returns the name of the UI which should be stored by the
  556.     //    caller for later use in performing operations on the collection UI.
  557.     //
  558.  
  559.     // Create the lookup table if it does not already exist.
  560.     //
  561.     createCollectionUILookupTable();
  562.  
  563.     if ($hypershadeName == "")
  564.     {
  565.         // There is no existing hyperShade editor to reuse, so we will create a
  566.         // new one.
  567.         //
  568.         $hypershadeName = generateUniqueHypershadeName();
  569.         hyperGraph -unParent $hypershadeName;
  570.         hyperGraph 
  571.             -edit 
  572.             -zoom 0.75
  573.             $hypershadeName;
  574.         hyperShade
  575.             -setAllowsRegraphing false
  576.             $hypershadeName;
  577.         hyperUserInit($hypershadeName);
  578.     }
  579.  
  580.     string $collectionUI;
  581.  
  582.  
  583.     $collectionUI = `formLayout collection`;
  584.         // Register the collectionUI in the lookup table
  585.         //
  586.         registerCollectionUI($collectionUI);
  587.         registerHypershadeName($collectionUI, $hypershadeName);
  588.  
  589.         hyperGraph 
  590.             -edit
  591.             -parent $collectionUI
  592.             $hypershadeName;
  593.  
  594.         formLayout
  595.             -edit
  596.             -af $hypershadeName top        0
  597.             -af $hypershadeName bottom    0
  598.             -af $hypershadeName left    0 
  599.             -af $hypershadeName right    0
  600.             $collectionUI;
  601.     setParent ..; // from $collectionUI
  602.     formLayout 
  603.         -edit
  604.         -af $collectionUI top         0
  605.         -af $collectionUI bottom     0
  606.         -af $collectionUI left         0
  607.         -af $collectionUI right         0
  608.         $parentFormLayout;
  609.  
  610.     return $collectionUI;
  611. }
  612.  
  613.